from fastapi import APIRouter, Depends, Request

from sqlmodel import Session

from app.admin.deps import get_db
from app.admin.service.system.login import SystemLoginService
from app.exception.base import unified_response
from app.models.system_admin import SystemLoginIn

router = APIRouter()


def get_log_service(request: Request, session: Session = Depends(get_db)) -> SystemLoginService:
    return SystemLoginService(request, session)


@router.post('/login')
@unified_response
async def login(request: Request,
                data_in: SystemLoginIn,
                     service: SystemLoginService = Depends(get_log_service)):
    """登录系统"""
    return await service.login(data_in)


@router.post('/logout')
@unified_response
async def logout(request: Request,
                     service: SystemLoginService = Depends(get_log_service)):
    """退出登录"""
    return await service.logout()
